package com.yanqu.road.server.cmd.palace;

import com.yanqu.road.entity.estatewar.palace.PalaceAideJoinApply;
import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.palace.CrossPalaceActivity;
import com.yanqu.road.server.manager.palace.CrossPalaceActivityMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_PALACE_AIDE_JOIN_APPLY_LIST, desc = "获取申请列表")
public class CrossPalaceAideJoinApplyListCmd extends CrossCommand {
    private long userId;
    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        EstateWarProto.PalaceAideJoinApplyListReqMsg reqMsg = EstateWarProto.PalaceAideJoinApplyListReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        List<PalaceAideJoinApply> dataList = null;
        CrossPalaceActivity crossPalaceActivity = CrossPalaceActivityMgr.getCrossPalaceActivity(activityId);
        if(null != crossPalaceActivity){
            dataList = crossPalaceActivity.getPalaceAideJoinApplyList(userId);
        }
        EstateWarProto.PalaceAideApplyListMsg.Builder listMsg = CrossPalaceActivityMgr.parsePalaceAideApplyListMsg(dataList);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_PALACE_AIDE_APPLY_LIST, listMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
